package com.my.controller;


import com.alibaba.fastjson.JSONArray;
import com.my.bean.AlreadyAppointment;
import com.my.bean.ResultPage;
import com.my.bean.SysDic;
import com.my.bean.VoPage;
import com.my.service.AlreadyAppointmentService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 已经预约产康项目安排 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2018-08-26
 */
@Controller
@RequestMapping("/alreadyAppointment")
public class AlreadyAppointmentController {

    @Autowired
    AlreadyAppointmentService alreadyAppointmentService;

    //输出日志创建一个Logger对象
    Logger logger = Logger.getLogger(AlreadyAppointmentController.class);
    /**
     * 跳转页面
     * @return  页面
     */
    @RequestMapping("/noOrderHandling")
    public String noOrderHandling(){
        return "noOrder_handling";

    }


    /**
     * 查询所有的房间id和房间号
     * @return  查询的数据
     */
    @RequestMapping("/selectAlreadyAppointment")
    @ResponseBody
    public List<AlreadyAppointment> select(HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }

        List<AlreadyAppointment> list = alreadyAppointmentService.selectResult(admin);
        //日志输出
        logger.info("List:"+list);
        return list;
    }


    /**
     * 根据房间id查询每个房间有哪些项目
     * @param alreadyAppointment
     * @return 返回每个房间对应每个房间的项目
     */
    @RequestMapping("/selectHomeById")
    @ResponseBody
    public List<AlreadyAppointment> selectHomeById(AlreadyAppointment alreadyAppointment,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }

        List<AlreadyAppointment> list = alreadyAppointmentService.selectHomeById(alreadyAppointment.getHomeId(),admin);
        //日志输出
        logger.info("list:"+list);
        return list;
    }

    /**
     * 添加功能产康项目安排
     * @param alreadyAppointment
     * @return 添加产康项目
     */
    @RequestMapping("/insert")
    @ResponseBody
    public boolean insert(AlreadyAppointment alreadyAppointment){
        boolean flag = alreadyAppointmentService.insert(alreadyAppointment);
        String msg = flag?"添加成功"+alreadyAppointment:"添加失败";
        logger.info(msg);
        return flag;
    }

















}
